package com.linkage.jz.bankruptcy.fragment.Project;

import android.content.Context;
import android.graphics.PointF;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.LinearSmoothScroller;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;


import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.linkage.jz.bankruptcy.BankruptcyApp;
import com.linkage.jz.bankruptcy.Consts;
import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.activity.Project.ApplyProNoticeActivity;
import com.linkage.jz.bankruptcy.activity.Project.ProDetailActivity;
import com.linkage.jz.bankruptcy.activity.Project.ZQUser.CreateZQOneProjectActivity;
import com.linkage.jz.bankruptcy.activity.Project.ZQUser.EditZQUserBaseInfoActivity;
import com.linkage.jz.bankruptcy.adapter.FileAdapter;
import com.linkage.jz.bankruptcy.base.BaseActivity;
import com.linkage.jz.bankruptcy.bean.MyProInfo;
import com.linkage.jz.bankruptcy.bean.MyProInfoAuth;
import com.linkage.jz.bankruptcy.bean.TaskAtta;
import com.linkage.jz.bankruptcy.bean.TokenInfo;
import com.linkage.jz.bankruptcy.bean.ZQUserDetailBaseInfo;
import com.linkage.jz.bankruptcy.net.BaseSubscriber;
import com.linkage.jz.bankruptcy.net.Network;
import com.linkage.jz.bankruptcy.utils.SPUtils;
import com.linkage.jz.bankruptcy.utils.Utils;
import com.linkage.jz.bankruptcy.widget.LoginNoticeDialog;
import com.linkage.jz.bankruptcy.widget.PublicNoticeDialog;
import com.linkage.jz.bankruptcy.widget.ShapeLoadingDialog;
import com.linkage.seapeak.activity.register.RegisterActivity;
import com.linkage.seapeak.activity.user.ImageShowActivity;
import com.linkage.seapeak.pojo.ManagersInfo;
import com.linkage.seapeak.pojo.TempProject;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * @author FT
 * @time 2016-07-18 16:49
 */

// JUMP 
public class ProDetailFragment extends Fragment {
    RecyclerView mRecyclerView;
    private             Context     context;
    private             int         mPage;
    public static final String      MERCHANT_DETAILS_PAGE = "MERCHANT_DETAILS_PAGE";
    private             DemoAdapter mAdapter;

    private        LinearLayout id_bottom,id_bottom2,id_bottom3;
    private static MyProInfo    mInfo;

    private ShapeLoadingDialog shapeLoadingDialog;

    public RecyclerView mFileRecyclerView7;
    public FileAdapter mFileAdapter7;
    public List<TaskAtta> list7= new ArrayList<>();;


    public RecyclerView mFileRecyclerView1;
    public FileAdapter mFileAdapter1;
    public List<TaskAtta> list1= new ArrayList<>();;


    public RecyclerView mFileRecyclerView2;
    public FileAdapter mFileAdapter2;
    public List<TaskAtta> list2= new ArrayList<>();;


    public RecyclerView mFileRecyclerView3;
    public FileAdapter mFileAdapter3;
    public List<TaskAtta> list3= new ArrayList<>();;


    public static ProDetailFragment newInstance( int page, MyProInfo info ) {
        Bundle args = new Bundle();
        args.putInt(MERCHANT_DETAILS_PAGE, page);
        mInfo = info;
        ProDetailFragment tripFragment = new ProDetailFragment();
        tripFragment.setArguments(args);
        return tripFragment;
    }

    @Override
    public void onCreate( Bundle savedInstanceState ) {
        super.onCreate(savedInstanceState);
        mPage = getArguments().getInt(MERCHANT_DETAILS_PAGE);
        context = getActivity().getApplicationContext();
        shapeLoadingDialog = new ShapeLoadingDialog(getActivity());
//        getData();
    }

    @Nullable
    @Override
    public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState ) {
        View view = inflater.inflate(R.layout.fragment_pro_detailpro_about, container, false);
        mRecyclerView = view.findViewById(R.id.mRecyclerView);
        id_bottom = (LinearLayout) view.findViewById(R.id.id_bottom);
        id_bottom2 = (LinearLayout) view.findViewById(R.id.id_bottom2);
        id_bottom3 = (LinearLayout) view.findViewById(R.id.id_bottom3);

        TextView btn_commit = (TextView)view.findViewById (R.id.btn_commit);
        btn_commit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                noticeDialog = new PublicNoticeDialog(getActivity(), new View.OnClickListener() {
                    @Override
                    public void onClick( View view ) {
                        String  sendStatus = "";
                        if (view.getId() == R.id.btn_chancel_notice) {//暂存
                            sendStatus = "1";
                            noticeDialog.dismiss();
                        } else if (view.getId() == R.id.ll_close) {
                            if (noticeDialog != null && noticeDialog.isShowing())
                                noticeDialog.dismiss();
                            return;
                        } else {//生成
                            sendStatus = "2";
                            noticeDialog.dismiss();
                            accpectOrRefData(mInfo.getId(), "2");
                        }

                        noticeDialog.dismiss();

                    }
                }, 1, "提示", "确定拒绝邀请?\n拒绝邀请后将导致无法线上申报债权、参与表决等操作！", "取消", "确定");
                noticeDialog.show();
            }
        });

        TextView btn_commit2 = (TextView)view.findViewById (R.id.btn_commit2);
        btn_commit2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                String userToken = SPUtils.getInstance(Consts.SPNAME).getString("userToken", "");
                if ("".equalsIgnoreCase(userToken)) {
                    noticeDialog = new PublicNoticeDialog(getActivity(), new View.OnClickListener() {
                        @Override
                        public void onClick( View view ) {
                            switch (view.getId()) {
                                case R.id.ll_close:
                                    noticeDialog.dismiss();
                                    break;

                                case R.id.btn_chancel_notice:
                                    noticeDialog.dismiss();

                                    break;

                                case R.id.btn_save_notice:
                                    RegisterActivity.start(getActivity());
                                    noticeDialog.dismiss();
                                    break;

                            }

                        }
                    }, 1, "提示", "操作此功能，需要请您先注册/登录",
                            "取消", "确认");
                    noticeDialog.show();
                    return;
                }else {
                    ApplyProNoticeActivity.start(getActivity(),mInfo.getId(),mInfo.getCreditorId(),mInfo.getSysAddressId(), mInfo.getContacts(),mInfo.getContactPhone());
                }

            }
        });

        TextView btn_commit3 = (TextView)view.findViewById (R.id.btn_commit3);
        btn_commit3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                ApplyProNoticeActivity.start(getActivity(), mInfo.getId(), mInfo.getCreditorId(),mInfo.getManagerId(),"管理人",mInfo.getContacts());


                String userToken = SPUtils.getInstance(Consts.SPNAME).getString("userToken", "");
                if ("".equalsIgnoreCase(userToken)) {
                    noticeDialog = new PublicNoticeDialog(getActivity(), new View.OnClickListener() {
                        @Override
                        public void onClick( View view ) {
                            switch (view.getId()) {
                                case R.id.ll_close:
                                    noticeDialog.dismiss();
                                    break;

                                case R.id.btn_chancel_notice:
                                    noticeDialog.dismiss();

                                    break;

                                case R.id.btn_save_notice:
                                    RegisterActivity.start(getActivity());
                                    noticeDialog.dismiss();
                                    break;

                            }

                        }
                    }, 1, "提示", "操作此功能，需要请您先注册/登录",
                            "取消", "确认");
                    noticeDialog.show();
                    return;
                }else {
                    ZQUserDetailBaseInfo info = new ZQUserDetailBaseInfo();
                    info.setBankruptcyProjectId(mInfo.getId());
                    info.setId(mInfo.getCreditorId());
                    CreateZQOneProjectActivity.start(getActivity(),info,mInfo.getSysAddressId(), mInfo.getContacts(),mInfo.getContactPhone());
                }

            }
        });

        TextView btn_commit4 = (TextView)view.findViewById (R.id.btn_commit4);
        btn_commit4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                ZQUserDetailBaseInfo info = new ZQUserDetailBaseInfo();
//                info.setBankruptcyProjectId(mInfo.getId());
//                info.setId(mInfo.getCreditorId());
////                CreateZQOneProjectActivity.start(getActivity(), info,info.getManagerId(),"管理人",info.getContacts());
////                ApplyProNoticeActivity.start(getActivity(),mInfo.getId(),mInfo.getCreditorId());
//                EditZQUserBaseInfoActivity.start(getActivity(), info, 1, 0);
//                ApplyProNoticeActivity.start(getActivity(),mInfo.getId(),mInfo.getCreditorId(),mInfo.getSysAddressId(),"管理人",mInfo.getSendMobile());
                String userToken = SPUtils.getInstance(Consts.SPNAME).getString("userToken", "");
                if ("".equalsIgnoreCase(userToken)) {
                    noticeDialog = new PublicNoticeDialog(getActivity(), new View.OnClickListener() {
                        @Override
                        public void onClick( View view ) {
                            switch (view.getId()) {
                                case R.id.ll_close:
                                    noticeDialog.dismiss();
                                    break;

                                case R.id.btn_chancel_notice:
                                    noticeDialog.dismiss();

                                    break;

                                case R.id.btn_save_notice:
                                    RegisterActivity.start(getActivity());
                                    noticeDialog.dismiss();
                                    break;

                            }

                        }
                    }, 1, "提示", "操作此功能，需要请您先注册/登录",
                            "取消", "确认");
                    noticeDialog.show();
                    return;
                }else {
                    ApplyProNoticeActivity.start(getActivity(),mInfo.getId(),mInfo.getCreditorId(),mInfo.getSysAddressId(), mInfo.getContacts(),mInfo.getContactPhone());
                }
            }
        });

        return view;
    }

    @Override
    public void onActivityCreated( @Nullable Bundle savedInstanceState ) {
        super.onActivityCreated(savedInstanceState);
        mRecyclerView.setLayoutManager(new LinearLayoutManagerWithSmoothScroller(getActivity()));
        List<String> content = new ArrayList<>();
        content.add("这个Adapter非要一个ArrayList做Count的填充, getItemCount都不好使");
        mAdapter = new DemoAdapter(R.layout.fragment_pro_detailpro_about_item, content);
        mAdapter.openLoadAnimation();

        mRecyclerView.setAdapter(mAdapter);//设置adapter

        mRecyclerView.smoothScrollToPosition(0);


    }

    @Override
    public void onResume() {
        super.onResume();
        ProDetailActivity parentActivity = (ProDetailActivity) getActivity();
        parentActivity.showLoading();
        if (mInfo != null && !"".equalsIgnoreCase(mInfo.getJoinId()) && "0".equalsIgnoreCase(mInfo.getJoinType()) && "0".equalsIgnoreCase(mInfo.getAcceptInvitation())) {
            id_bottom.setVisibility(View.VISIBLE);
        } else {
            id_bottom.setVisibility(View.GONE);
        }
        getData();

        mAdapter.notifyDataSetChanged();
    }
   private PublicNoticeDialog noticeDialog;

    /**
     * adapter
     */
    class DemoAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

        public DemoAdapter( int LayoutId, List<String> list ) {
            super(R.layout.fragment_pro_detailpro_about_item, list);
        }

        @Override
        public void convert( BaseViewHolder helper, String str ) {
//            String tmp ="";
            if(mInfo== null)
            {
                return;
            }
            linearLayout1 = (LinearLayout)helper.getView(R.id.linearLayout1 );
            helper.setText(R.id.tvproabout, Utils.tmpString(mInfo.getProjectNote()));

            helper.setVisible(R.id.tvproabout,true);

            helper.setText(R.id.tv_detail_proname, mInfo.getProjectName());
            if (mInfo == null) {
                return;
            }
            String strType = "";
            if ("0".equalsIgnoreCase(mInfo.getProjectType())) {
                strType = "破产清算";
            }
            if ("1".equalsIgnoreCase(mInfo.getProjectType())) {
                strType = "破产重整";
            }
            if ("2".equalsIgnoreCase(mInfo.getProjectType())) {
                strType = "破产和解";
            }
            if ("3".equalsIgnoreCase(mInfo.getProjectType())) {
                strType = "其他";
            }
            helper.setText(R.id.tvprotype, strType);


            helper.setText(R.id.tvpromanagegroup, Utils.tmpString(mInfo.getCourtName()));

            helper.setText(R.id.tvpronum,  Utils.tmpString(mInfo.getCaseNumber()));



            String str1 = "";
            String str2 = "";
            String managersName = "";
            String managersAdministrator = "";
            String socialUniformCreditCode = "";
            removeView();
                for(int i=0;i<mInfo.getManagersList().size();i++)
                {
                    ManagersInfo info = mInfo.getManagersList().get(i);

                    int type = 0;
                    if("0".equalsIgnoreCase(info.getManagersType())) {
                        managersName = info.getManagersName();
                        managersAdministrator = info.getManagersAdministrator();
                        socialUniformCreditCode = info.getSocialUniformCreditCode();
                        type = 0;
                    } else {
                        managersName = info.getManagersName();
                        type = 1;
                    }

                    addView(type,managersName,managersAdministrator,socialUniformCreditCode);

                }


            //管理人名称
//            tmp = str2;
//            helper.setText(R.id.tvadd1,Utils.tmpString(str2));
//            //管理人负责人
//
//            helper.setText(R.id.tvadd2,Utils.tmpString(str1));
//            //社会信用代码
//
//
//            helper.setText(R.id.tvadd3,Utils.tmpString(mInfo.getSocialUniformCreditCode()));
            //联系人
            helper.setText(R.id.tvadd4, Utils.tmpString(mInfo.getContacts()));
//            //联系电话
            helper.setText(R.id.tvadd5, Utils.tmpString(mInfo.getContactPhone()));



            //债务人法定代表人

            helper.setText(R.id.tvadd6, Utils.tmpString(mInfo.getDebtorLegalRepresentative()));

            //债务人住所地

            helper.setText(R.id.tvadd7, Utils.tmpString(mInfo.getDebtorAddressDetail()));

            try {

//                if(mFileRecyclerView7==null) {
                     mFileRecyclerView7 = helper.getView(R.id.recycler_files7);
                     mFileAdapter7 = new FileAdapter(getActivity(), list7);
                    mFileRecyclerView7.setLayoutManager(mFileAdapter7.createLayoutManager());
//                mFileAdapter1.openLoadAnimation();
                    mFileRecyclerView7.setAdapter(mFileAdapter7);


                     mFileRecyclerView1 = helper.getView(R.id.recycler_files1);
                     mFileAdapter1 = new FileAdapter(getActivity(), list1);
                    mFileRecyclerView1.setLayoutManager(mFileAdapter1.createLayoutManager());
//                mFileAdapter1.openLoadAnimation();
                    mFileRecyclerView1.setAdapter(mFileAdapter1);

                     mFileRecyclerView2 = helper.getView(R.id.recycler_files2);
                     mFileAdapter2 = new FileAdapter(getActivity(),list2);
                    mFileRecyclerView2.setLayoutManager(mFileAdapter2.createLayoutManager());
//                mFileAdapter2.openLoadAnimation();
                    mFileRecyclerView2.setAdapter(mFileAdapter2);

                     mFileRecyclerView3 = helper.getView(R.id.recycler_files3);
                     mFileAdapter3 = new FileAdapter(getActivity(),list3);
                    mFileRecyclerView3.setLayoutManager(mFileAdapter3.createLayoutManager());
//                mFileAdapter3.openLoadAnimation();
                    mFileRecyclerView3.setAdapter(mFileAdapter3);
//                }

                helper.setVisible(R.id.tvprorecefile7, mInfo.getDebtorYyzzFileListStrList().size() == 0);
                helper.setVisible(R.id.tvprorecefile, mInfo.getCourtSlwsFileList().size() == 0);
                helper.setVisible(R.id.tvpromanagerfile, mInfo.getCourtManagerFileList().size() == 0);
                helper.setVisible(R.id.tvprootherfile, mInfo.getOtherFileList().size() == 0);


                mRecyclerView.smoothScrollToPosition(0);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 转化图片地址
     *
     * @param imageBundle
     * @return
     */
    private List<String> getImageList( String imageBundle ) throws JSONException {
        List<String> imgList = new ArrayList<>();
        JSONArray    array   = new JSONArray(imageBundle);
        for (int i = 0; i < array.length(); i++) {
            JSONObject item    = array.optJSONObject(i);
            String     itemUrl = item.optString("attachmentWatermarkAddress");
            imgList.add(itemUrl);
        }
        return imgList;
    }

    /**
     * 展示item的
     */
    class ImageAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

        //区别类型
        List<String> data;

        public ImageAdapter( int layoutResId, @Nullable List<String> data ) {
            super(layoutResId, data);
//            Log.e("=========----====prodetail2", layoutResId + "");
            this.data = data;
        }

        @Override
        protected void convert( final BaseViewHolder helper, String item ) {
            ImageView imgItem = helper.getView(R.id.item_image);
            Glide.with(context).load(item)
                    .into(imgItem);
            imgItem.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick( View v ) {
                    ImageShowActivity.start(getActivity(), (ArrayList<String>) data,
                                            helper.getAdapterPosition(), ImageShowActivity.FROM_MUlTI_SHOW);
                }
            });
        }
    }

    /**
     * 再次获取数据
     */
    public void getData() {
        if (mInfo == null || mInfo.getId() == null) {
            return;
        }

        String userToken = SPUtils.getInstance(Consts.SPNAME).getString("userToken", "");
        Network
                .getAPIService()
                .getProjectDetailInfo(userToken, mInfo.getId())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<JsonObject>() {
                    @Override
                    public void onNext( JsonObject json ) {
                        int code = json.get("code").getAsInt();
                        if (code != 0) {
//                            super.onNext(json);
                            return;
                        }
                        JsonObject data = json.getAsJsonObject("data");

                        JsonArray arr1 = data.getAsJsonArray("attachmentSLWSList");
                        JsonArray arr2 = data.getAsJsonArray("attachmentGLSWSList");
                        JsonArray arr3 = data.getAsJsonArray("attachmentOtherList");
                        JsonArray arr4 = data.getAsJsonArray("attachmentYYZZList");
                        TempProject tempProject = new Gson().fromJson(json.getAsJsonObject("data")
                                .toString(), TempProject.class);
                        MyProInfo myProInfo = new MyProInfo();
                        mInfo = tempProject.turnData(myProInfo);

//                        JsonArray arr4 = data.getAsJsonArray("courtManagerFileList");

                        if (arr1 != null) {
                            mInfo.getCourtSlwsFileList().clear();
                            mInfo.getCourtSlwsFileList().addAll(TaskAtta.parse(arr1));

                        }else{
                            mInfo.getCourtSlwsFileList().clear();
                        }
                        list1 = mInfo.getCourtSlwsFileList();
                        if (arr2 != null) {
                            mInfo.getCourtManagerFileList().clear();
                            mInfo.getCourtManagerFileList().addAll(TaskAtta.parse(arr2));
                        }
                        list2 = mInfo.getCourtManagerFileList();
                        if (arr3 != null) {
                            mInfo.getOtherFileList().clear();
                            mInfo.getOtherFileList().addAll(TaskAtta.parse(arr3));
                        }
                        list3 = mInfo.getOtherFileList();
                        if (arr4 != null) {
                            mInfo.getDebtorYyzzFileListStrList().clear();
                            mInfo.getDebtorYyzzFileListStrList().addAll(TaskAtta.parse(arr4));
                        }
                        list7 = mInfo.getDebtorYyzzFileListStrList();
//                        MyProInfoAuth auth = data.getAsJsonObject("courtManagerFileList");
                        MyProInfoAuth auth = new Gson().fromJson(json.getAsJsonObject("data")
                                .getAsJsonObject("auth").toString(), MyProInfoAuth.class);

                        mInfo.setAuth(auth);
                        if (mInfo.getAuth().getAcceptOrReject()) {
                            id_bottom.setVisibility(View.VISIBLE);
                        } else {
                            id_bottom.setVisibility(View.GONE);
                        }

                        if (mInfo.getAuth().getFillingIn()) {
                            id_bottom2.setVisibility(View.VISIBLE);
                        } else {
                            id_bottom2.setVisibility(View.GONE);
                        }

                        if (mInfo.getAuth().getAllowJoin()) {
                            id_bottom3.setVisibility(View.VISIBLE);
                        } else {
                            id_bottom3.setVisibility(View.GONE);
                        }


                        mAdapter.notifyDataSetChanged();
                    }

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError( Throwable e ) {
                    }
                });
    }


    public void accpectOrRefData(String msgId, String type) {
        shapeLoadingDialog.setLoadingText("加载中...");
        shapeLoadingDialog.setCanceledOnTouchOutside(false);
        shapeLoadingDialog.show();
        OkHttpClient okHttpClient = new OkHttpClient();
        Random random = new Random();
        String rom = random.nextLong() + "";
        String timestamp = System.currentTimeMillis() + "";
        String userToken = SPUtils.getInstance(Consts.SPNAME).getString("userToken", "");

        if ("".equalsIgnoreCase(userToken)) {
            return;
        }
        RequestBody requestBody = new FormBody.Builder()
                .add("appid", Consts.appid)
                .add("nonce", rom)
                .add("timestamp", timestamp)
                .add("token", BankruptcyApp.tokeninfo.getToken())
                .add("userToken", userToken)
                .add("projectId", msgId)
                .add("opType", type)
                .build();

        String url = Consts.WEBURL_ACCORREF;
        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .build();

        okHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
//                Log.d(TAG, "onFailure: " + e.getMessage());
                shapeLoadingDialog.dismiss();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
//                Log.d(TAG, response.protocol() + " " +response.code() + " " + response.message());
                Headers headers = response.headers();
                shapeLoadingDialog.dismiss();


                String str = response.body().string();
                try {
                    final JSONObject object = new JSONObject(str);

                    if  (object.optInt("code") == -10004 || (object.optInt("code") == -10003))
                    {

                        getActivity().runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                LoginNoticeDialog.showPage(object.optString("msg"));
                            }

                        });

                        return;
                    }
                    if (object.optInt("code") == 0) {
//
//                        Toast.makeText(PhoneLoginActivity.this,"请求成功，请查看短信"+object.optString("data"),Toast.LENGTH_SHORT).show();
                        getActivity().runOnUiThread(new Runnable() {

                            @Override
                            public void run() {

//                                getList();
                                getData();

                                Toast.makeText(getActivity(), "操作成功", Toast.LENGTH_SHORT).show();
                            }

                        });

                    } else {
                        getActivity().runOnUiThread(new Runnable() {

                            @Override
                            public void run() {

                                Toast.makeText(getActivity(), "操作失败:" + object.optString("msg"), Toast.LENGTH_SHORT).show();
                            }

                        });
                    }


                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
    }

    public class LinearLayoutManagerWithSmoothScroller extends LinearLayoutManager {

        public LinearLayoutManagerWithSmoothScroller(Context context) {
            super(context, VERTICAL, false);
        }

        public LinearLayoutManagerWithSmoothScroller(Context context, int orientation, boolean reverseLayout) {
            super(context, orientation, reverseLayout);
        }

        @Override
        public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state,
                                           int position) {
            RecyclerView.SmoothScroller smoothScroller = new TopSnappedSmoothScroller(recyclerView.getContext());
            smoothScroller.setTargetPosition(position);
            startSmoothScroll(smoothScroller);
        }

        private class TopSnappedSmoothScroller extends LinearSmoothScroller {
            public TopSnappedSmoothScroller(Context context) {
                super(context);

            }

            @Override
            public PointF computeScrollVectorForPosition(int targetPosition) {
                return LinearLayoutManagerWithSmoothScroller.this
                        .computeScrollVectorForPosition(targetPosition);
            }

            @Override
            protected int getVerticalSnapPreference() {
                return SNAP_TO_START;
            }
        }
    }

    private LinearLayout linearLayout1;
    private void removeView(){

        for(int i=0;i<editViews.size();i++) {
            View view = editViews.get(i);
            linearLayout1.removeView(view);
            editViews.remove(view);
        }
    }

    private ArrayList<View> editViews = new ArrayList<View>();
    private void addView(int type,String managersName,String managersAdministrator, String socialUniformCreditCode ){
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.activity_pro_detail_manager_item1, null);

        TextView tv_title1 = (TextView)view.findViewById(R.id.tv_title1);
        TextView tvadd1 = (TextView)view.findViewById(R.id.tvadd1);
        TextView tvadd2 = (TextView)view.findViewById(R.id.tvadd2);
        TextView tvadd3 = (TextView)view.findViewById(R.id.tvadd3);

        if(type == 0) {
            view.findViewById(R.id.ll_tv1).setVisibility(View.VISIBLE);
            view.findViewById(R.id.ll_tv2).setVisibility(View.VISIBLE);
            view.findViewById(R.id.ll_tv3).setVisibility(View.VISIBLE);
            tv_title1.setText("管理人名称：    ");
            tvadd1.setText(managersName);
            tvadd2.setText(managersAdministrator);
            tvadd3.setText(socialUniformCreditCode);
        }else{
            view.findViewById(R.id.ll_tv1).setVisibility(View.VISIBLE);
            view.findViewById(R.id.ll_tv2).setVisibility(View.GONE);
            view.findViewById(R.id.ll_tv3).setVisibility(View.GONE);
            tv_title1.setText("管理人姓名：    ");
            tvadd1.setText(managersName);
        }



        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        linearLayout1.addView(view, params);

        editViews.add(view);
    }

}
